define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/code/lists/index' + location.search,
                    add_url: 'pay/code/lists/add',
                    edit_url: 'pay/code/lists/edit',
                    del_url: 'pay/code/lists/del',
                    multi_url: 'pay/code/lists/multi',
                    import_url: 'pay/code/lists/import',
                    table: 'pay_code_lists',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'platform.name', title: __('Platform.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: {"禁用":__('禁用'),"正常":__('正常')}, formatter: Table.api.formatter.status},
                        {field: 'merchant_no', title: __('Merchant_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'platform_lists_id', title: __('Platform_lists_id')},
                        {field: 'paytype', title: __('Paytype'), searchList: {"wechat":__('Wechat'),"alipay":__('Alipay'),"unionpay":__('Unionpay')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'appid', title: __('Appid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'codetype', title: __('Codetype'), searchList: {"0":__('Codetype 0'),"1":__('Codetype 1')}, formatter: Table.api.formatter.normal},
                        {field: 'codetype', title: __('Codetype'), formatter: function (value, row, index){
                                if (value == 0){
                                    return '通用';
                                }else{
                                    return '定向';
                                }
                            }},
                        {field: 'isarea', title: __('Isarea'), formatter: function (value, row, index){
                                if (value == 0){
                                    return '否';
                                }else{
                                    return '是';
                                }
                            }},

                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                                {
                                    name: 'detail',
                                    title: __('弹出窗口打开'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'pay/code/area?ref=addtabs',
                                    extend:'data-area=["100%","100%"]',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                            ], formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
